const Koa = require('koa')
const koaStatic = require("koa-static");
const koaMount = require('koa-mount')
const path = require('path')

const app = new Koa()
const resolve = file => path.resolve(__dirname, file);

const router  = require('./router')
app.use(async (ctx, next) => {
    const start = new Date()
    await next()
    const ms = new Date() - start
    console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
})
app.use(router.routes()).use(router.allowedMethods())
// 开放目录
app.use(koaMount('/dist', koaStatic(resolve("../dist"))));
// 在服务器处理函数中……
module.exports = app
